import { defineConfig, loadEnv } from "vite";
import AutoImport from "unplugin-auto-import/vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { viteMockServe } from "vite-plugin-mock";
import vueJsx from "@vitejs/plugin-vue-jsx";
export default ({ mode }) => {
  return defineConfig({
    plugins: [
      vueJsx(),
      vue(),
      Components({ dirs: ["src/components"], dts: true, resolvers: [ElementPlusResolver()] }),
      AutoImport({
        resolvers: [ElementPlusResolver()],
        dts: true,
        imports: ["vue", "vue-router", { "@/request/request_one.ts": ["hfoRequest"] }, { "@/request/request_two.ts": ["hftRequest"] }]
      }),
      viteMockServe({ watchFiles: false, mockPath: "mock" })
    ],
    resolve: { alias: { "@": path.resolve(__dirname, "src") }, extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"] },
    build: {
      minify: "terser",
      terserOptions: { compress: { drop_console: true, drop_debugger: true } },
      rollupOptions: { output: { entryFileNames: `assets/[name].[hash].js`, chunkFileNames: `assets/[name].[hash].js`, assetFileNames: `assets/[name].[hash].[ext]` } }
    },
    server: {
      port: parseInt(loadEnv(mode, process.cwd()).VITE_LOCAL_PORT),
      cors: true,
      proxy: {
        "/api": { target: loadEnv(mode, process.cwd()).VITE_APP_PROXY_URL, changeOrigin: true, rewrite: (path) => path.replace(/api/, "") }
      }
    }
  });
};
